﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using TestMySqlConnetPoll;
using DevExpress.XtraEditors.Repository;
using System.Threading;
using View.Common;
using DevExpress.XtraCharts;

namespace View.Chart.DC
{
    public partial class DCSZTimeCurve : DevExpress.XtraEditors.XtraForm
    {
        private DcdlqxTable dcqx = new DcdlqxTable();
        private float now_dotnum;
        public DCSZTimeCurve()
        {
            InitializeComponent();

            //初始化曲线名称
            IniCurveNameList();
            if (repositoryItemComboBox2.Items.Count > 0)
                this.cBoxCurveName.EditValue = (this.cBoxCurveName.Edit as RepositoryItemComboBox).Items[0];
            repositoryItemComboBox2.SelectedIndexChanged += new EventHandler(CBoxCurveName_SelectedIndexChanged);
            if (repositoryItemComboBox3.Items.Count > 0)
                this.cBoxCurveTime.EditValue = (this.cBoxCurveTime.Edit as RepositoryItemComboBox).Items[0];
            repositoryItemComboBox3.SelectedIndexChanged += new EventHandler(CBoxCurveTime_SelectedIndexChanged);
        }

        /// <summary>
        /// 查找数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void CBoxCurveTime_SelectedIndexChanged(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
        }

        /// <summary>
        /// 添加一条曲线
        /// </summary>
        /// <param name="seriesName"></param>
        /// <param name="chart"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        private void CreateSeries(string seriesName, ChartControl chart, List<ObjValue> values)
        {
            //初始化Series
            Series series = new Series();
            series.ArgumentScaleType = ScaleType.DateTime;
            series.ValueScaleType = ScaleType.Numerical;
            series.Label.Border.Visible = false;
            series.Label.BackColor = Color.Transparent;
            series.CrosshairLabelVisibility = DevExpress.Utils.DefaultBoolean.False;
            series.ChangeView(ViewType.Spline);
            series.CrosshairEnabled = DevExpress.Utils.DefaultBoolean.True;
            series.CrosshairHighlightPoints = DevExpress.Utils.DefaultBoolean.True;
            series.LegendText = seriesName;
            series.ToolTipEnabled = DevExpress.Utils.DefaultBoolean.True;

            chart.Series.Add(series);

            List<SeriesPoint> points = new List<SeriesPoint>();
            int index = 0;

            foreach (ObjValue qxA in values)
            {
                index++;
                SeriesPoint point = new SeriesPoint(index, qxA.Value);
                points.Add(point);
            }
            AddPoints(series, points);
        }

        /// <summary>
        /// 给一条曲线添加一组点
        /// </summary>
        /// <param name="series"></param>
        /// <param name="pointsToUpdate"></param>
        private void AddPoints(Series series, List<SeriesPoint> pointsToUpdate)
        {
            series.Points.AddRange(pointsToUpdate.ToArray());
        }

        /// <summary>
        /// 曲线名称改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void CBoxCurveName_SelectedIndexChanged(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// 初始化曲线名称列表
        /// </summary>
        private void IniCurveNameList()
        {
            //cBoxCurveName.ite
            foreach (objDcdlqxStruct strkey in c_Device.DcdlqxDevList)
                this.repositoryItemComboBox2.Items.Add(strkey.DevName);

        }

        private void BtnPrint_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void BtnExport_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void BtnClose_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }
    }
}